package com.hopool.shop.dao.product;

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.hopool.shop.dao.DaoBaseTest;
import com.hopool.shop.product.Product;
import com.hopool.shop.product.ProductType;

public class ProductDaoTest extends DaoBaseTest{
	private ProductDao pd = (ProductDao) ctx.getBean("productDao");
	
	public void testBaseCRUD(){
		Session s = ((SessionFactory)ctx.getBean("sessionFactory")).openSession();
		Product p = new Product();
		p.setCode("10001");
		p.setCreateDate(new Date());
		p.setName("test");
		p.setStatus("1");
		s.beginTransaction();
		s.save(p);
		p.setName("testUpdate");
		Product pDB = (Product) s.get(Product.class, p.getId());
		assertEquals("testUpdate", pDB.getName());
		s.getTransaction().commit();
		s.beginTransaction();
		s.delete(p);
		s.getTransaction().commit();
		s.beginTransaction();
		Product pDB2 = (Product) s.get(Product.class, p.getId());
		assertNull(pDB2);
		s.getTransaction().commit();
	}
	
	public void testPage(){
		Product p = new Product();
		p.setCode("10");
		p.setName("t");
		ProductType pt = new ProductType();
		pt.setId(2L);
		pt.setName("test");
		p.setProductType(pt);
		pd.page(p, 0, 10,"asc","productType");
	}
	
	public void testCount(){
		Product p = new Product();
		p.setCode("10");
		p.setName("t");
		int i = pd.count(p,"productType");
	}
}
